package com.example.biz.impl;

import com.example.biz.TopicBiz;
import com.example.dao.TopicMapper;
import com.example.dao.TopictypeMapper;
import com.example.entity.Topic;
import com.example.entity.TopicExample;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

import java.util.Collections;
import java.util.List;

@Service
public class TopicBizImpl implements TopicBiz{
    @Resource
    private TopictypeMapper topictypeMapper;
    @Resource
    private TopicMapper topicMapper;

    @Override
    public List<Topic> queryByType(Integer ttype) {
        TopicExample topicExample=new TopicExample();
        topicExample.createCriteria().andTtypeEqualTo(ttype);
        List<Topic> list=topicMapper.selectByExample(topicExample);
        Collections.shuffle(list);//打亂順序
        return list;
    }

    @Override
    public Integer checkright(List<Topic> list) {
        Integer point=0;
        for (Topic topic : list) {
            if (topic.getTright().equals(queryByTid(topic.getTright()).getTright())){
                point++;
            }
        }
        return point;
    }

    @Override
    public Topic queryByTid(int tid) {
        return topicMapper.selectByPrimaryKey(tid);
    }


}
